home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / epic / epic.sty < prev    next >
Text File  |  1991-01-30  |  26KB  |  560 lines

  1. \typeout{%
  2. Enhancements to Picture Environment. Version 1.2 - Released June 1, 1986}
  3. %----------------------------------------------------------------------
  4. % Copyright (C) podar@sbcs (Sunil Podar) July 14,1986.
  5. % You may use this file in whatever way you wish. You are requested to 
  6. % leave this notice intact, and report any bugs, enhancements, comments,
  7. % suggestions, etc. to:
  8. % USmail: Sunil Podar,Dept. of Computer Science,SUNY at Stony Brook,NY 11794.
  9. %  CSNET: podar@sbcs.csnet
  10. %   ARPA: podar%suny-sb.csnet@csnet-relay.arpa
  11. %   UUCP: {allegra, hocsd, philabs, ogcvax}!sbcs!podar
  12. %----------------------------------------------------------------------
  13. % This file contains implementation of:
  14. % \multiputlist    \matrixput    \grid        \picsquare
  15. % \dottedline    \dashline    \drawline    \jput
  16. % \putfile
  17. % Environments: dottedjoin, dashjoin and drawjoin
  18. %
  19. % For documentation, see the accompanying manual.
  20. %----------------------------------------------------------------------
  21. % usage: \multiputlist(x,y)(delta-x,delta-y)[tbrl]{item1,item2,item3,.....}
  22. % \lop and \lopoff taken from TeXbook.
  23. %----------------------------------------------------------------------
  24. \def\lop#1\to#2{\expandafter\lopoff#1\lopoff#1#2}
  25. \long\def\lopoff,#1,#2\lopoff#3#4{\def#4{#1}\def#3{,#2}}
  26. \def\@@mlistempty{,}
  27. \newif\iflistnonempty
  28. \def\multiputlist(#1,#2)(#3,#4){\@ifnextchar
  29. [{\@imultiputlist(#1,#2)(#3,#4)}{\@imultiputlist(#1,#2)(#3,#4)[]}}
  30.  
  31. \long\def\@imultiputlist(#1,#2)(#3,#4)[#5]#6{{%
  32. \@xdim=#1\unitlength \@ydim=#2\unitlength
  33. \listnonemptytrue \def\@@mlist{,#6,} % need this for end condition
  34. \loop
  35. \lop\@@mlist\to\@@firstoflist
  36. \@killglue\raise\@ydim\hbox to\z@{\hskip
  37. \@xdim\@imakepicbox(0,0)[#5]{\@@firstoflist}\hss}
  38. \advance\@xdim #3\unitlength\advance\@ydim #4\unitlength
  39. \ifx\@@mlist\@@mlistempty \listnonemptyfalse\fi
  40. \iflistnonempty
  41. \repeat\relax
  42. \ignorespaces}}
  43. %----------------------------------------------------------------------
  44. % two-dimensional version of \multiput
  45. % \matrixput(0,0)(20,0){5}(0,20){3}{\circle{2}}
  46. %----------------------------------------------------------------------
  47. \newcount\@@multicnt
  48. \def\matrixput(#1,#2)(#3,#4)#5(#6,#7)#8#9{%
  49. \ifnum#5>#8\@matrixput(#1,#2)(#3,#4){#5}(#6,#7){#8}{#9}%
  50. \else\@matrixput(#1,#2)(#6,#7){#8}(#3,#4){#5}{#9}\fi}
  51.  
  52. %% here #5 >= #8
  53. \long\def\@matrixput(#1,#2)(#3,#4)#5(#6,#7)#8#9{{\@killglue%
  54. \@multicnt=#5\relax\@@multicnt=#8\relax%
  55. \@xdim=0pt%
  56. \@ydim=0pt%
  57. \setbox\@tempboxa\hbox{\@whilenum \@multicnt > 0\do {%
  58. %%\typeout{\the\@multicnt, \the\@@multicnt}%
  59. \raise\@ydim\hbox to \z@{\hskip\@xdim #9\hss}%
  60. \advance\@multicnt \m@ne%
  61. \advance\@xdim #3\unitlength\advance\@ydim #4\unitlength}}%
  62. \@xdim=#1\unitlength%
  63. \@ydim=#2\unitlength%
  64. \@whilenum \@@multicnt > 0\do {%
  65. \raise\@ydim\hbox to \z@{\hskip\@xdim \copy\@tempboxa\hss}%
  66. \advance\@@multicnt \m@ne%
  67. \advance\@xdim #6\unitlength\advance\@ydim #7\unitlength}%
  68. \ignorespaces}}
  69. %----------------------------------------------------------------------
  70. %\grid(wd,ht)(delta-wd,delta-ht)[initial-X-integer,initial-Y-integer]
  71. % example: 1. \put(0,0){\grid(95,100)(9.5,10)}
  72. %          2. \put(0,0){\grid(100,100)(10,5)[-10,0]}
  73. %          or \put(0,0){\tiny \grid(100,100)(5,5)[0,0]}%numbers in \tiny font
  74. %----------------------------------------------------------------------
  75. \newcount\d@lta
  76. \newdimen\@delta
  77. \newdimen\@@delta
  78. \newcount\@gridcnt
  79. \def\grid(#1,#2)(#3,#4){\@ifnextchar [{\@igrid(#1,#2)(#3,#4)}%
  80. {\@igrid(#1,#2)(#3,#4)[@,@]}}
  81.  
  82. \long\def\@igrid(#1,#2)(#3,#4)[#5,#6]{%
  83. \makebox(#1,#2){%
  84. \@delta=#1pt\@@delta=#3pt\divide\@delta \@@delta\d@lta=\@delta%
  85. \advance\d@lta \@ne\relax\message{grid=\the\d@lta\space x}%
  86. %% copied the definition of \line(0,1){#2} for some efficiency!.
  87. \multiput(0,0)(#3,0){\d@lta}{\hbox to\z@{\hskip -\@halfwidth \vrule
  88.      \@width \@wholewidth \@height #2\unitlength \@depth \z@\hss}}%
  89. \ifx#5@\relax\else%
  90. \global\@gridcnt=#5%
  91. \multiput(0,0)(#3,0){\d@lta}{%
  92. \makebox(0,-2)[t]{\number\@gridcnt\global\advance\@gridcnt by #3}}%
  93. \global\@gridcnt=#5%
  94. \multiput(0,#2)(#3,0){\d@lta}{\makebox(0,0)[b]{\number\@gridcnt\vspace{2mm}%
  95. \global\advance\@gridcnt by #3}}%
  96. \fi%
  97. \@delta=#2pt\@@delta=#4pt\divide\@delta \@@delta\d@lta=\@delta%
  98. \advance\d@lta \@ne\relax\message{\the\d@lta . }%
  99. %% copied the definition of \line(1,0){#1} for some efficiency!.
  100. \multiput(0,0)(0,#4){\d@lta}{\vrule \@height \@halfwidth \@depth \@halfwidth
  101.      \@width #1\unitlength}%
  102. \ifx#6@\relax\else
  103. \global\@gridcnt=#6%
  104. \multiput(0,0)(0,#4){\d@lta}{%
  105. \makebox(0,0)[r]{\number\@gridcnt\ \global\advance\@gridcnt by #4}}%
  106. \global\@gridcnt=#6%
  107. \multiput(#1,0)(0,#4){\d@lta}{%
  108. \makebox(0,0)[l]{\ \number\@gridcnt\global\advance\@gridcnt by #4}}%
  109. \fi}}
  110. %----------------------------------------------------------------------
  111. % \picsquare is a centered square of dimensions governed by \thinlines,
  112. % \thicklines or \linethickness declarations.
  113. \def\picsquare{\hskip -0.5\@wholewidth%
  114. \vrule height \@halfwidth depth \@halfwidth width \@wholewidth}
  115. %
  116. % just a square dot with reference point at bottom-left
  117. \def\picsquare@bl{\vrule height \@wholewidth depth \z@  width \@wholewidth}
  118. %----------------------------------------------------------------------
  119. % \begin{dottedjoin}{interdot-gap in units}
  120. % .....            
  121. % \end{dottedjoin}
  122. % \begin{dashjoin}{dash-length in units}{interdotgap in each dash}
  123. % .....            
  124. % \end{dashjoin}
  125. % \begin{drawjoin}
  126. % .....
  127. % \end{drawjoin}
  128. % \jput(x,y){character}
  129. % \dottedline[opt. dotcharacter]{dotgap in units}(x1,y1)(x2,y2)...(xN,yN)
  130. % \dashline[#]{dash-length}[opt. dotgap](x1,y1)(x2,y2)...(xN,yN)
  131. % \drawline[#](x1,y1)(x2,y2)...(xN,yN)
  132. %----------------------------------------------------------------------
  133. % definitions for *join environment. had to do all this mess because of
  134. % optional arguments.
  135. %----------------------------------------------------------------------
  136. \newif\if@jointhem \global\@jointhemfalse
  137. \newif\if@firstpoint \global\@firstpointtrue
  138. \newcount\@joinkind
  139. %\newenvironment{dottedjoin}[1]%[opt char]{dotgap}
  140. %{\global\@jointhemtrue \gdef\dotgap@join{#1}\global\@joinkind=0\relax}%
  141. %{\global\@jointhemfalse \global\@firstpointtrue}
  142. %----------------------------------------------------------------------
  143. \def\dottedjoin{\global\@jointhemtrue \global\@joinkind=0\relax
  144.   \bgroup\@ifnextchar[{\@idottedjoin}{\@idottedjoin[\picsquare@bl]}}
  145. \def\@idottedjoin[#1]#2{\gdef\dotchar@join{#1}\gdef\dotgap@join{#2}}
  146. \def\enddottedjoin{\global\@jointhemfalse \global\@firstpointtrue\egroup}
  147. %----------------------------------------------------------------------
  148. \def\dashjoin{\global\@jointhemtrue \global\@joinkind=1\relax
  149.   \bgroup\@ifnextchar[{\@idashjoin}{\@idashjoin[\dashlinestretch]}}
  150. \def\@idashjoin[#1]#2{\edef\dashlinestretch{#1}\gdef\dashlen@join{#2}%
  151. \@ifnextchar[{\@iidashjoin}{\gdef\dotgap@join{}}}
  152. \def\@iidashjoin[#1]{\gdef\dotgap@join{#1}}
  153. \let\enddashjoin\enddottedjoin
  154. %----------------------------------------------------------------------
  155. \def\drawjoin{\global\@jointhemtrue \global\@joinkind=2\relax
  156.   \bgroup\@ifnextchar[{\@idrawjoin}{}}
  157. \def\@idrawjoin[#1]{\def\drawlinestretch{#1}}
  158. \let\enddrawjoin\enddottedjoin
  159. %----------------------------------------------------------------------
  160. %% this is equiv to \put(x,y){#1} when not in {dot*join} environment.
  161. \long\def\jput(#1,#2)#3{{\@killglue\raise#2\unitlength\hbox to \z@{\hskip
  162. #1\unitlength #3\hss}\ignorespaces}
  163. \if@jointhem
  164.  \if@firstpoint \gdef\x@one{#1} \gdef\y@one{#2} \global\@firstpointfalse
  165.  \else\ifcase\@joinkind
  166.     \@dottedline[\dotchar@join]{\dotgap@join\unitlength}%
  167. (\x@one\unitlength,\y@one\unitlength)(#1\unitlength,#2\unitlength)
  168.     \or\@dashline[\dashlinestretch]{\dashlen@join}[\dotgap@join]%
  169. (\x@one,\y@one)(#1,#2)
  170.     \else\@drawline[\drawlinestretch](\x@one,\y@one)(#1,#2)\fi
  171.     \gdef\x@one{#1} \gdef\y@one{#2}
  172.  \fi
  173. \fi}
  174. %----------------------------------------------------------------------
  175. \newdimen\@dotgap
  176. \newdimen\@ddotgap
  177. \newcount\@x@diff
  178. \newcount\@y@diff
  179. \newdimen\x@diff
  180. \newdimen\y@diff
  181. \newbox\@dotbox
  182. \newcount\num@segments
  183. \newcount\num@segmentsi
  184. \newif\ifsqrt@done
  185. %% from sqrtandstuff func basically need \num@segments.
  186. %% given a deltax, deltay and dotgap, it calculates \num@segments = number of
  187. %% segments along the hypotenuse. used by \dottedline & \dashline.
  188. %% It finishes quickly if any of deltax or deltay are zero or close to zero.
  189. \def\sqrtandstuff#1#2#3{
  190. \ifdim #1 <0pt \@x@diff= -#1 \else\@x@diff=#1\fi
  191. \ifdim #2 <0pt \@y@diff= -#2 \else\@y@diff=#2\fi
  192. %% @diff's will be positive and diff's will retain their sign.
  193. \@dotgap=#3 \divide\@dotgap \tw@
  194. \advance\@x@diff \@dotgap \advance\@y@diff \@dotgap% for round-off errors
  195. \@dotgap=#3
  196. \divide\@x@diff \@dotgap \divide\@y@diff \@dotgap
  197. \sqrt@donefalse
  198. \ifnum\@x@diff < 2
  199.    \ifnum\@y@diff < 2 \num@segments=\@x@diff \advance\num@segments \@y@diff
  200.               \sqrt@donetrue
  201.         \else\num@segments=\@y@diff \sqrt@donetrue\fi
  202.    \else\ifnum\@y@diff < 2 \num@segments=\@x@diff \sqrt@donetrue\fi
  203. \fi
  204. \ifsqrt@done \ifnum\num@segments=\z@ \num@segments=\@ne\fi\relax
  205.  \else \ifnum\@y@diff >\@x@diff
  206.          \@tempcnta=\@x@diff \@x@diff=\@y@diff \@y@diff=\@tempcnta
  207.        \fi            %exchange @x@diff & @y@diff, so now @x@diff > @y@diff
  208.   \num@segments=\@y@diff
  209.   \multiply\num@segments \num@segments
  210.   \multiply\num@segments by 457
  211.   \divide\num@segments \@x@diff
  212.   \advance\num@segments by 750 % for round-off, going to divide by 1000.
  213.   \divide\num@segments \@m
  214.   \advance\num@segments \@x@diff
  215.         %num@segments = @x@diff + (0.457*sqr(@y@diff)/@x@diff)
  216. \fi}
  217. %----------------------------------------------------------------------
  218. % \dottedline[opt. char]{interdot gap in units}(x1,y1)(x2,y2)....(xN,yN)
  219. %----------------------------------------------------------------------
  220. %% Used the following construction earlier but that results in box memory
  221. %% full much too soon although it works perfectly.
  222. %% \setbox\@dotbox\vbox to\z@{\vss \hbox to\z@{\hss #1\hss}\vss}\relax}
  223. %% The cenetering of characters is achieved by substracting half the ht, wd
  224. %% of character from the (x,y) coordinates where they are to be put. We
  225. %% chose to use a macro for the ``dot'' instead of \copy\box to save memory
  226. %% at the expense of extra cpu, since memory becomes an issue very soon.
  227. %% \picsquare is already centered, whereas other characters, except \circle,
  228. %% will not be cenetered, hence to handle them all in a similar fashion,
  229. %% used \picsquare@bl.
  230. %
  231. % kind of tail recursion.
  232. \def\dottedline{\@ifnextchar [{\@idottedline}{\@idottedline[\picsquare@bl]}}
  233. \def\@idottedline[#1]#2(#3,#4){\@ifnextchar (%
  234. {\@iidottedline[#1]{#2}(#3,#4)}{\relax}}
  235. \def\@iidottedline[#1]#2(#3,#4)(#5,#6){\@dottedline[#1]{#2\unitlength}%
  236. (#3\unitlength,#4\unitlength)(#5\unitlength,#6\unitlength)%
  237. \@idottedline[#1]{#2}(#5,#6)}
  238. %
  239. %% user not supposed to use this directly. arguments in absolute dimensions.
  240. %% need to pass absolute dimens here because dashline calls dottedline and
  241. %% can supply only absolute dimensions.
  242. \long\def\@dottedline[#1]#2(#3,#4)(#5,#6){{%
  243. \x@diff=#5\relax\advance\x@diff by -#3\relax
  244. \y@diff=#6\relax\advance\y@diff by -#4\relax
  245. \sqrtandstuff{\x@diff}{\y@diff}{#2}
  246. \divide\x@diff \num@segments
  247. \divide\y@diff \num@segments
  248. \advance\num@segments \@ne     % to put the last point at destination.
  249. %%\typeout{num@segments= \the\num@segments}
  250. \setbox\@dotbox\hbox{#1}% just to get the dimensions of the character.
  251. \@xdim=#3 \@ydim=#4
  252. \ifdim\ht\@dotbox >\z@% otherwise its a circle.
  253.   \advance\@xdim -0.5\wd\@dotbox
  254.   \advance\@ydim -0.5\ht\@dotbox
  255.   \advance\@ydim .5\dp\@dotbox\fi
  256. %%circle's have a ht=0, this is one way I could think of to catch circles.
  257. %%following loop is equiv to
  258. %%\multiput(\@xdim,\@ydim)(\x@diff,\y@diff){\num@segments}{#1}
  259. %%with arguments in absolute dimensions.
  260. \@killglue
  261. \loop \ifnum\num@segments > 0
  262. \unskip\raise\@ydim\hbox to\z@{\hskip\@xdim #1\hss}%
  263. \advance\num@segments \m@ne\advance\@xdim\x@diff\advance\@ydim\y@diff%
  264. \repeat
  265. \ignorespaces}}
  266. %----------------------------------------------------------------------
  267. % \dashline[#]{dash-length}[optional dotgap](x1,y1)(x2,y2)...(xN,yN)
  268. % The minimum # of dashes put is 2, one at either end point; dash-length is
  269. % reduced accordingly if necessary. Also have to some dirty work to account
  270. % for stretch & shrink.
  271. % \renewcommand{\dashlinestretch}{-50}  %ONLY INTEGERS PERMITTED.
  272. %----------------------------------------------------------------------
  273. \def\dashlinestretch{0} %well, could have used a counter.
  274. \def\dashline{\@ifnextchar [{\@idashline}{\@idashline[\dashlinestretch]}}
  275. \def\@idashline[#1]#2{\@ifnextchar [{\@iidashline[#1]{#2}}%
  276. {\@iidashline[#1]{#2}[\@empty]}} %\@empty needed-- later checked with \ifx 
  277. \def\@iidashline[#1]#2[#3](#4,#5){\@ifnextchar (%
  278. {\@iiidashline[#1]{#2}[#3](#4,#5)}{\relax}}
  279. %
  280. \def\@iiidashline[#1]#2[#3](#4,#5)(#6,#7){%
  281. \@dashline[#1]{#2}[#3](#4,#5)(#6,#7)%
  282. \@iidashline[#1]{#2}[#3](#6,#7)}
  283. %
  284. \long\def\@dashline[#1]#2[#3](#4,#5)(#6,#7){{%
  285. \x@diff=#6\unitlength \advance\x@diff by -#4\unitlength
  286. \y@diff=#7\unitlength \advance\y@diff by -#5\unitlength
  287. %% correction to get actual width since the dash-length as taken in arguement
  288. %% is the center-to-center of the end-points.
  289. \@tempdima=#2\unitlength \advance\@tempdima -\@wholewidth
  290. \sqrtandstuff{\x@diff}{\y@diff}{\@tempdima}
  291. \ifnum\num@segments <3 \num@segments=3\fi% min number of dashes I can plot
  292. % is 2, 1 at either end, thus min num@segments is 3 (including 'empty dash').
  293. \@tempdima=\x@diff \@tempdimb=\y@diff
  294. \divide\@tempdimb by\num@segments
  295. \divide\@tempdima by\num@segments
  296. %% ugly if-then-else. If optional dotgap specified, then use it otherwise
  297. %% make a solid looking dash.
  298. {\ifx#3\@empty \relax
  299.     \ifdim\@tempdima < 0pt \x@diff=-\@tempdima\else\x@diff=\@tempdima\fi
  300.     \ifdim\@tempdimb < 0pt \y@diff=-\@tempdimb\else\y@diff=\@tempdimb\fi
  301.     \ifdim\x@diff < 0.3pt %it's a vertical dashline
  302.            \ifdim\@tempdimb > 0pt
  303.             \global\setbox\@dotbox\hbox{\hskip -\@halfwidth \vrule
  304.          \@width \@wholewidth \@height \@tempdimb}
  305.        \else\global\setbox\@dotbox\hbox{\hskip -\@halfwidth \vrule
  306.          \@width \@wholewidth \@height\z@ \@depth -\@tempdimb}\fi
  307.        \else\ifdim\y@diff < 0.3pt %it's a horizontal dashline
  308.                \ifdim\@tempdima >0pt
  309.           \global\setbox\@dotbox\hbox{\vrule \@height \@halfwidth
  310.                  \@depth \@halfwidth \@width \@tempdima}
  311.         \else\global\setbox\@dotbox\hbox{\hskip \@tempdima
  312.              \vrule \@height \@halfwidth \@depth \@halfwidth
  313.                  \@width -\@tempdima \hskip \@tempdima}\fi
  314.         \else\global\setbox\@dotbox\hbox{%
  315. \@dottedline[\picsquare]{0.98\@wholewidth}(0pt,0pt)(\@tempdima,\@tempdimb)}
  316. \fi\fi
  317. \else\global\setbox\@dotbox\hbox{%
  318. \@dottedline[\picsquare]{#3\unitlength}(0pt,0pt)(\@tempdima,\@tempdimb)}
  319. \fi}
  320. \advance\x@diff by -\@tempdima % both have same sign
  321. \advance\y@diff by -\@tempdimb
  322. %
  323. %%here we correct the number of dashes to be put by reducing them
  324. %%appropriately. (num@segments*\@wholewidth) is in some way the slack we
  325. %%have,and division by dash-length gives the reduction. reduction =
  326. %%(2*num@segments*\@wholewidth)/dash-length
  327. %% (num@segments includes empty ones)
  328. \@tempdima=\num@segments\@wholewidth \@tempdima=2\@tempdima 
  329. \@tempcnta=\@tempdima \@tempdima=#2\unitlength \@tempdimb=0.5\@tempdima
  330. \@tempcntb=\@tempdimb \advance\@tempcnta by \@tempcntb % round-off error
  331. \divide\@tempcnta by\@tempdima \advance\num@segments by -\@tempcnta
  332. %
  333. \ifnum #1=0 \relax\else\ifnum #1 < -100
  334.   \typeout{***dashline: reduction > -100 percent implies blankness!***}
  335. \else\num@segmentsi=#1 \advance\num@segmentsi by 100
  336.      \multiply\num@segments by\num@segmentsi \divide\num@segments by 100
  337. \fi\fi
  338. %
  339. \divide\num@segments by 2 % earlier num@segments included 'empty dashes' too.
  340. \ifnum\num@segments >0 % if =0 then don't divide => \x@diff & \y@diff
  341.  \divide\x@diff by\num@segments%   remain same.
  342.  \divide\y@diff by\num@segments
  343.  \advance\num@segments by\@ne %for the last segment for which I subtracted
  344.                   %\@tempdima & \@tempdimb from \x@diff & \y@diff
  345.  \else\num@segments=2 % one at each end.
  346. \fi
  347. %%\typeout{num@segments finally = \the\num@segments}
  348. %% equiv to \multiput(#4,#5)(\x@diff,\y@diff){\num@segments}{\copy\@dotbox}
  349. %% with arguements in absolute dimensions.
  350. \@xdim=#4\unitlength \@ydim=#5\unitlength
  351. \@killglue
  352. \loop \ifnum\num@segments > 0
  353. \unskip\raise\@ydim\hbox to\z@{\hskip\@xdim \copy\@dotbox\hss}%
  354. \advance\num@segments \m@ne\advance\@xdim\x@diff\advance\@ydim\y@diff%
  355. \repeat
  356. \ignorespaces}}
  357. %----------------------------------------------------------------------
  358. %%1.00   .833333  .80  .75  .66666   .60  .50  .40  .33333    .25 .20  .16666
  359. %% .916666 .816666 .775 .708333 .633333 .55 .45 .366666 .291666 .225 .183333
  360. %% 0.0
  361. %%0.083333
  362. %% the first line has absolute slopes corresponding to various permissible
  363. %% integer combinations representing slopes. The second line is the midpoint
  364. %% of all those slopes (attempted to show them in the middle of two entries).
  365. %%
  366. %% \lineslope(x@diff dimen, y@diff dimen)
  367. %% Given base (x@diff) and height (y@diff) in dimensions, determines the
  368. %% closest available slope and returns the two required integers in \@xarg
  369. %% and \@yarg. The given base and height can be ANYTHING, -ve or +ve, or
  370. %% even 0pt. \lineslope knows about (0,1) and (1,0) slopes too and returns
  371. %% correct values if the conditions regarding x@diff & y@diff are obeyed
  372. %% (see NOTE). Used by \drawline. This is the simplest and only way I could
  373. %% figure out to accomplish it!.
  374. %% NOTE: both the dimensions (x@diff & y@diff) must be in SAME units and the
  375. %% larger of the two dimensions must be atleast 1pt (i.e. 65536sp). To avoid
  376. %% dividing by 0, I make the larger dimension = 1pt if it is < 1pt.
  377. %% will need a similar one for vectors, or maybe this can be used. For
  378. %% vectors the range is -4, 4 unlike lines where it is -6, 6.
  379. \newif\if@flippedargs
  380. \def\lineslope(#1,#2){%
  381. \ifdim #1 <0pt \@xdim= -#1 \else\@xdim=#1\fi
  382. \ifdim #2 <0pt \@ydim= -#2 \else\@ydim=#2\fi
  383. %%\typeout{xdim,ydim= \the\@xdim, \the\@ydim}
  384. \ifdim\@xdim >\@ydim \@tempdima=\@xdim \@xdim=\@ydim \@ydim=\@tempdima
  385. \@flippedargstrue\else\@flippedargsfalse\fi% x < y
  386. \ifdim\@ydim >1pt \@tempcnta=\@ydim
  387.             \divide\@tempcnta by 65536% now \@tempcnta=integral part of #1.
  388.             \divide\@xdim \@tempcnta\fi
  389. \ifdim\@xdim <.083333pt \@xarg=1 \@yarg=0
  390.  \else\ifdim\@xdim <.183333pt    \@xarg=6 \@yarg=1
  391.  \else\ifdim\@xdim <.225pt     \@xarg=5 \@yarg=1
  392.  \else\ifdim\@xdim <.291666pt     \@xarg=4 \@yarg=1
  393.  \else\ifdim\@xdim <.366666pt     \@xarg=3 \@yarg=1
  394.  \else\ifdim\@xdim <.45pt     \@xarg=5 \@yarg=2
  395.  \else\ifdim\@xdim <.55pt     \@xarg=2 \@yarg=1
  396.  \else\ifdim\@xdim <.633333pt     \@xarg=5 \@yarg=3
  397.  \else\ifdim\@xdim <.708333pt     \@xarg=3 \@yarg=2
  398.  \else\ifdim\@xdim <.775pt     \@xarg=4 \@yarg=3
  399.  \else\ifdim\@xdim <.816666pt     \@xarg=5 \@yarg=4
  400.  \else\ifdim\@xdim <.916666pt     \@xarg=6 \@yarg=5
  401.        \else            \@xarg=1 \@yarg=1%
  402. \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
  403. \if@flippedargs\relax\else\@tempcnta=\@xarg \@xarg=\@yarg
  404.               \@yarg=\@tempcnta\fi
  405. \ifdim #1 <0pt \@xarg= -\@xarg\fi
  406. \ifdim #2 <0pt \@yarg= -\@yarg\fi
  407. %%\typeout{closest slope integers = \the\@xarg, \the\@yarg}
  408. }
  409. %----------------------------------------------------------------------
  410. % usage: \drawline[#](x1,y1)(x2,y2)....(xN,yN)
  411. %                % # is an optional integer between -100 & infinity.
  412. % \renewcommand{\drawlinestretch}{-50}  %ONLY INTEGERS PERMITTED.
  413. %----------------------------------------------------------------------
  414. \newif\if@toosmall
  415. \newif\if@drawit
  416. \newif\if@horvline
  417. \def\drawlinestretch{0} %well, could have used a counter.
  418. % kind of tail recursion.
  419. \def\drawline{\@ifnextchar [{\@idrawline}{\@idrawline[\drawlinestretch]}}
  420. \def\@idrawline[#1](#2,#3){\@ifnextchar ({\@iidrawline[#1](#2,#3)}{\relax}}
  421. \def\@iidrawline[#1](#2,#3)(#4,#5){\@drawline[#1](#2,#3)(#4,#5)
  422. \@idrawline[#1](#4,#5)}
  423. %
  424. \def\@drawline[#1](#2,#3)(#4,#5){{%
  425. \x@diff=#4\unitlength \advance\x@diff by -#2\unitlength
  426. \y@diff=#5\unitlength \advance\y@diff by -#3\unitlength
  427. %% override any linethickness declarations, and since horiz & vertical lines
  428. %% come out thinner than the slanted ones, assign slightly larger values.
  429. %% default values are: thinlines=0.4pt, thicklines=0.8pt
  430. \ifx\@linefnt\tenln \linethickness{0.5pt} \else \linethickness{0.9pt}\fi
  431. \lineslope(\x@diff,\y@diff)% returns the two integers in \@xarg & \@yarg.
  432. %------
  433. \@toosmalltrue
  434. {\ifdim\x@diff <\z@ \x@diff=-\x@diff\fi
  435.  \ifdim\y@diff <\z@ \y@diff=-\y@diff\fi
  436.  \ifdim\x@diff >10pt \global\@toosmallfalse\fi
  437.  \ifdim\y@diff >10pt \global\@toosmallfalse\fi}
  438. %------
  439. %% For efficiency, if the line is horiz or vertical then we draw it in one
  440. %% shot, only if the stretch is not -ve and the line is not too small.
  441. \@drawitfalse\@horvlinefalse
  442. \ifnum#1 <0 \relax\else\@horvlinetrue\fi
  443. \if@toosmall\@horvlinetrue\fi% to get 'or' condition. We necessarily draw a 
  444. % solid line if the line is too small ignoring any -ve stretch.
  445. \if@horvline
  446.  \ifdim\x@diff =0pt \put(#2,#3){\ifdim\y@diff >0pt \@linelen=\y@diff \@upline
  447.                  \else\@linelen=-\y@diff \@downline\fi}%
  448.  \else\ifdim\y@diff =0pt
  449.           \ifdim\x@diff >0pt \put(#2,#3){\vrule \@height \@halfwidth \@depth
  450.                 \@halfwidth \@width \x@diff}
  451.         \else \put(#4,#5){\vrule \@height \@halfwidth \@depth
  452.                 \@halfwidth \@width -\x@diff}\fi
  453.        \else\@drawittrue\fi\fi % construct the line explicitly
  454. \else\@drawittrue\fi
  455. %-------------------------------
  456. \if@drawit
  457. \ifnum\@xarg< 0 \@negargtrue\else\@negargfalse\fi
  458. \ifnum\@xarg =0 \setbox\@linechar%
  459. \hbox{\hskip -\@halfwidth \vrule \@width \@wholewidth \@height 10.2pt
  460.  \@depth \z@}
  461. \else \ifnum\@yarg =0 \setbox\@linechar%
  462. \hbox{\vrule \@height \@halfwidth \@depth \@halfwidth \@width 10.2pt}
  463. \else \if@negarg \@xarg -\@xarg \@yyarg -\@yarg
  464.         \else \@yyarg \@yarg\fi
  465. \ifnum\@yyarg >0 \@tempcnta\@yyarg \else \@tempcnta -\@yyarg\fi
  466. \setbox\@linechar\hbox{\@linefnt\@getlinechar(\@xarg,\@yyarg)}%
  467. \fi\fi
  468. %------
  469. \if@toosmall% => it isn't a horiz or vert line and is toosmall.
  470.   \@dottedline[\picsquare]{.98\@wholewidth}%
  471. (#2\unitlength,#3\unitlength)(#4\unitlength,#5\unitlength)%
  472. \else
  473. %% following is neat. The last segment takes \wd\@linechar & \ht\@linechar
  474. %% so plot the line as though it were from (#2,#3) to
  475. %% (#4-\wd\@linechar,#5-\ht\@linechar) (i.e. for positive slope; of course,
  476. %% signs are reversed for other slopes). For horizontal & vertical dashes we
  477. %% don't have to subtract the ht & wd resp. since they are already centered.
  478. \ifnum\@xarg=0\relax\else\ifdim\x@diff >\z@ \advance\x@diff -\wd\@linechar
  479.   \else\advance\x@diff \wd\@linechar\fi\fi
  480. \ifnum\@yarg=0\relax\else\ifdim\y@diff >\z@\advance\y@diff -\ht\@linechar
  481.   \else\advance\y@diff \ht\@linechar\fi\fi
  482. \ifdim\x@diff <\z@ \@x@diff=-\x@diff \else\@x@diff=\x@diff\fi
  483. \ifdim\y@diff <\z@ \@y@diff=-\y@diff \else\@y@diff=\y@diff\fi
  484. %%\typeout{x@diff,y@diff=\the\x@diff , \the\y@diff}
  485. \num@segments=0 \num@segmentsi=0
  486. \ifdim\wd\@linechar >1pt
  487.  \num@segmentsi=\@x@diff \divide\num@segmentsi \wd\@linechar\fi
  488. \ifdim\ht\@linechar >1pt
  489.  \num@segments=\@y@diff \divide\num@segments \ht\@linechar\fi
  490. \ifnum\num@segmentsi >\num@segments \num@segments=\num@segmentsi\fi
  491. \advance\num@segments \@ne %to account for round-off error
  492. %
  493. \ifnum #1=0 \relax \else\ifnum #1 < -99
  494.   \typeout{***drawline: reduction <= -100 percent implies blankness!***}
  495. \else\num@segmentsi=#1 \advance\num@segmentsi by 100
  496.      \multiply\num@segments \num@segmentsi
  497.      \divide\num@segments by 100
  498.      \ifnum \num@segments=0 \num@segments=1 \fi
  499. \fi\fi
  500. %%\typeout{num@segments after = \the\num@segments}
  501. %
  502. \divide\x@diff \num@segments
  503. \divide\y@diff \num@segments
  504. \advance\num@segments \@ne %for the last segment for which I subtracted
  505.               %\wd & \ht of \@linechar from \@x@diff & \@y@diff.
  506. %%\typeout{numseg,x@diff,y@diff= \the\num@segments, \the\x@diff, \the\y@diff}
  507. %
  508. \@xdim=#2\unitlength \@ydim=#3\unitlength
  509. \if@negarg \advance\@xdim -\wd\@linechar\fi
  510. \ifnum\@yarg <0 \advance\@ydim -\ht\@linechar\fi
  511. %%following loop equiv to \multiput@abs(\@xdim,\@ydim)%
  512. %%(\x@diff,\y@diff){\num@segments}{\copy\@linechar}
  513. %%with arguements in absolute dimensions.
  514. \@killglue
  515. \loop \ifnum\num@segments > 0
  516. \unskip\raise\@ydim\hbox to\z@{\hskip\@xdim \copy\@linechar\hss}%
  517. \advance\num@segments \m@ne\advance\@xdim\x@diff\advance\@ydim\y@diff%
  518. \repeat
  519. \ignorespaces
  520. \fi%the if of @toosmall
  521. \fi}}% for \if@drawit
  522. %----------------------------------------------------------------------
  523. %usage: \putfile{datafile}{OBJECT}
  524. % The OBJECT is plotted at EACH of the coordinates read from the datafile.
  525. % The idea of these macros is to generate (x,y) pairs using some program
  526. % and then directly use those coordinates. Since TeX doesn't have real
  527. % floating point calculations, it is much more efficient and accurate to do
  528. % things this way. One can also use the unix facility 'spline' now to
  529. % generate smooth curves with equidistant ``dots''.
  530. % NOTE: the external file of coordinates must have x y pairs with a space
  531. % between them. Also it is suggested that some extension such as '.put'
  532. % be used for such datafiles to distinguish them in which case it must
  533. % be explicitely specified in the 1st argument so that TeX doesn't look
  534. % for a .tex extension.
  535. % The % char remains valid as a comment char and such lines are ignored;
  536. % however, there should be atleast one space after the second entry if a
  537. % comment is on the same line as data since % eats up the newline.
  538. %-----------------------------------------------------------------------
  539. \long\def\splittwoargs#1 #2 {(#1,#2)}
  540. %
  541. \newif\if@stillmore
  542. \newread\@datafile
  543. \long\def\putfile#1#2{\openin\@datafile = #1
  544. \@stillmoretrue
  545. \loop
  546. \ifeof\@datafile\relax\else\read\@datafile to\@dataline\fi
  547. %if file nonexistent, do nothing.
  548. \ifeof\@datafile\@stillmorefalse
  549. \else\ifx\@dataline\@empty \relax
  550.      \else
  551. \expandafter\expandafter\expandafter\put\expandafter\splittwoargs%
  552. \@dataline{#2}
  553.      \fi
  554. \fi
  555. \if@stillmore
  556. \repeat
  557. \closein\@datafile
  558. }
  559. %----------------------------------------------------------------------
  560.